package com.yxhl.zoume.core.specialcar.fragment;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jakewharton.rxbinding.view.RxView;
import com.yxhl.zoume.R;
import com.yxhl.zoume.SpecialCarFeeDetailDataBinding;
import com.yxhl.zoume.common.ui.fragment.BaseDataBindingFragment;
import com.yxhl.zoume.core.func.webpage.info.WebPageEntrance;
import com.yxhl.zoume.core.specialcar.model.SpecialCarFeeDetailModel;

import butterknife.BindView;
import butterknife.ButterKnife;
import rx.functions.Action1;

/**
 * Created by vhawk on 11/17/16.
 */

public class SpecialCarFeeDetailFragment extends BaseDataBindingFragment {

    private static final String KEY_SPECIAL_CAR_FEE_DETAIL = "SPECIAL_CAR_FEE_DETAIL";
    @BindView(R.id.tv_special_car_price_rule)
    TextView specialCarPriceRuleTv;
    private SpecialCarFeeDetailDataBinding specialCarFeeDetailDataBinding;
    private SpecialCarFeeDetailModel specialCarFeeDetailModel;

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        handlerExtraParam();
        specialCarFeeDetailDataBinding.setFeeDetail(specialCarFeeDetailModel);
        registerClickEvent();
    }

    private void registerClickEvent() {
        RxView.clicks(specialCarPriceRuleTv).subscribe(new Action1<Void>() {
            @Override
            public void call(Void aVoid) {
                // TODO: 11/17/16 等待跳转计价规则
                getAppComponent().navigator().navigateToWebPageActivity(getActivity(), WebPageEntrance.SPECIAL_CAR_PRICE_INTRODUCTION);
            }
        });
    }

    private void handlerExtraParam() {
        specialCarFeeDetailModel = (SpecialCarFeeDetailModel) getArguments().get(KEY_SPECIAL_CAR_FEE_DETAIL);
    }

    @Override
    protected void initializeInjector() {

    }

    @Override
    protected View getContentLayout(LayoutInflater inflater, ViewGroup container) {
        specialCarFeeDetailDataBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_special_fee_detail, container, false);
        return specialCarFeeDetailDataBinding.getRoot();
    }

    @Override
    protected void setupToolBar() {

    }

    public static Fragment newInstance(SpecialCarFeeDetailModel specialCarFeeDetailModel) {
        Fragment fragment = new SpecialCarFeeDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(KEY_SPECIAL_CAR_FEE_DETAIL, specialCarFeeDetailModel);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }
}
